define(['jquery', 'bootstrap', 'userend', 'table', 'form'], function ($, undefined, userend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mall/oper/inform/index',
                    add_url: 'mall/oper/inform/add',
                    detail_url: 'mall/oper/inform/detail',
                    table: 'mall_oper_inform',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'user_id', title: __('User_id'), visible:false},
                        {field: 'goods_id', title: __('Goods_id'), visible:false},
                        {field: 'shop_id', title: __('Shop_id'), visible:false},
                        {field: 'informType', title: __('Informtype'),searchList: {"1":__('Informtype 1'),"2":__('Informtype 2')}, formatter: Table.api.formatter.normal},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"2":__('State 2'),"3":__('State 3')}, formatter: Table.api.formatter.normal},
                        {field: 'admin_id', title: __('Admin_id'), visible:false},
                        {field: 'finalHandleTime', title: __('Finalhandletime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status, visible:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,events: Table.api.events.operate,
                            buttons: [{
                                name: 'detail',
                                text: __('Detail'),
                                classname: 'btn btn-xs btn-info btn-fields btn-dialog',
                                icon: 'fa fa-list',
                                url: 'mall/oper/inform/detail'
                            }],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});